SELECT spid from master..sysprocesses
WHERE blocked = 0
AND spid in (select blocked from master..sysprocesses)


SELECT count(*) from master..sysprocesses 
WHERE blocked <> 0 

SELECT spid from master..sysprocesses 
WHERE loginame = 'fbctorrance\ychoi'

SELECT 'kill ', spid from master..sysprocesses WHERE loginame = 'fbctorrance\ychoi'

SELECT TOP 5 * from master..sysprocesses
ORDER BY cpu DESC


SELECT spid, program_name, datediff(second,login_time, getdate()) as    
   ConnectedSeconds FROM master..sysprocesses WHERE spid > 50
   
   
   
   SELECT 
TOP 30
spid, blocked, 
    convert(varchar(25),db_name(dbid)) as DBName, 
    cpu, 
    datediff(second,login_time, getdate()) as Secs,
    convert(float, cpu / datediff(second,login_time, getdate())) as PScore,
    convert(varchar(16), hostname) as Host,
    convert(varchar(50), program_name) as Program,
    convert(varchar(20), loginame) as Login
FROM master..sysprocesses
WHERE datediff(second,login_time, getdate()) > 0 and spid > 50
ORDER BY pscore desc


SELECT 
    convert(varchar(50), program_name) as Program,
    count(*) as CliCount,
    sum(cpu) as CPUSum, 
    sum(datediff(second, login_time, getdate())) as SecSum,
    convert(float, sum(cpu)) / convert(float, sum(datediff(second, login_time, getdate()))) as Score,
    convert(float, sum(cpu)) / convert(float, sum(datediff(second, login_time, getdate()))) / count(*) as ProgramBadnessFactor
FROM master..sysprocesses
WHERE spid > 50
GROUP BY
    convert(varchar(50), program_name)
ORDER BY score DESC